#include "mytask.h"
#include <ConnectionPool.h>
#include <QDebug>
#include <QSqlQuery>

MyTask::MyTask(QObject *parent)
    : QObject{parent}
{
    // 如果任务被复用则不要填true，否则会被释放
    this->setAutoDelete(false);
}

void MyTask::setSql(QSqlDatabase *sql)
{
    sql = sql;
}


void MyTask::run()
{
    ConnectionPool *pool = ConnectionPool::getConnectionPool();
    QSqlDatabase *conn = pool->getConnection();
    QSqlQuery ss = conn->exec("select * from tb_user;");
    pool->closeConnection(conn); // 回收连接池
    qDebug()<< "当前的连接:" <<conn;
}
